<?php
/**
 * Created by PhpStorm.
 * User: Admin
 * Date: 2020-08-08
 * Time: 下午 04:08
 */
namespace Cmd;
use Cmd\Base\User;
use Lib\Cmd;

class Userdel extends User {
    public function main() {
        $username = $this->getArgv(0);

        if(empty($username)) {
            $this->help();
        }

        if(!$this->userModel->exists($username)) {
            $this->writeError('用户不存在');
        }

        if($this->userModel->del($username)) {
            $this->writeSuccess("删除用户 '$username'");
        }

        $this->writeError("删除用户失败");
    }
    
    public function help() {
        $this->writeInfo("功能: 删除用户");
        $this->writeInfo("用法: ./exec userdel (username)");
        $this->writeLn();
        $this->writeInfo("args:");
        $this->writeLn();
        $this->writeInfo("  username: 用户名");
        $this->writeLn();
    }
}